<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it" dir="ltr">
<head>
<title>.: {$title} :. {$page}</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<!--<link rel="stylesheet" type="text/css" media="screen" href="css/style.css" />-->
<!--<link rel="stylesheet" type="text/css" media="screen" href="css/menu.css" />-->
<link rel="stylesheet" type="text/css" media="screen" href="css/calendar.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/home.css" />

</head>

<body>
<form id="main" name="main" action="test.html">

<input type="text" id="testNumber" value="" onKeydown="return number(event,this, 30, 10, 2)" size="30"/><br />
<input type="text" name="testNumber1" value=""  /><br />
<input type="text" name="testNumber2" value=""  /><br />
<input type="text" name="testNumber3" id="testNumber3" value=""  /><br />
<input type="button" name="testNumber3" value="checkPIVA" onClick="ctrlIva('testNumber3')" /><br />

<!--iframe id="login"
frameborder="0"
name="login"
scrolling="no"
style="margin-left:0px; width:530px; height:570px; border:0px;"
allowtransparency="true"
src="http://app.tuotempo.com/customer.php?tool=searchreservations&dbName=tt_balla">
</iframe--> 

<script type="text/javascript">
var numValue = '';
var numValueTmp = '';
var numSpace = '                              ';
var numLen = 0;
var numKey;
var numInt = 0;
var numDec = 0;
var numChar = '';
	function ctrlIva( par )
	{
		alert( par );
		//checkPIVA2( par );
		if ( ! checkPIVA( par ) ) alert('Error 1');
	}
	
function number(e, obj, siz, int, dec)
{
	numTot = int + dec + 5;
	numKey = (window.event) ? e.keyCode : e.which;
	numValueTmp = '';
	
	if ( numKey == 8 )
	{
		numValue = numValue.substr(0, numValue.length - 1 );
	}
	else if ( numKey==188 )
	{
		numValue += ',';
	}
	else if ( 48 <= numKey && numKey <= 57 )
	{
		numValue += String.fromCharCode(numKey);
	}
	
	numLen = numValue.length
	numInt = 0;
	numDec = 0;
	while( numLen-- )
	{
		if ( numValue.substr( numLen , 1) == ',' )
		{
			numDec = numInt;
			numInt = 0;
		}
		else
		{
			numInt++;
		}
	}
	if ( numInt > int || numDec > dec ) 
	{
		numInt -= ( numInt > int ) ? 1 : 0 ;
		numDec -= ( numDec > dec ) ? 1 : 0 ;
		numValue = numValue.substr(0, numValue.length - 1 );
	}
	numLen = numValue.length
	numChar = '';
	while( numDec-- )
	{
		numLen--;
		numChar = numValue.substr( numLen , 1);
		numValueTmp = numValue.substr( numLen , 1) + numValueTmp;
	}
	if ( numChar != '' || numValue.charAt( numValue.length - 1 ) == ',' ) 
	{
		numValueTmp = ','+numValueTmp;
		numLen--;
	}
	numDec = 0;
	while( numInt-- )
	{
		numLen--;
		numDec++;
		if (numDec > 3)
		{
			numDec = 1;
			numValueTmp = '.' + numValueTmp;
		}
		numValueTmp = numValue.substr( numLen , 1) + numValueTmp;
	}	
	numLen = siz - numValueTmp.length;
	obj.value = numSpace.substr(0,numLen) + numValueTmp;

	e.returnValue = false;
	return false;
}

function checkCF( obj )
{
	var cf = document.getElementById( obj ).value.toUpperCase();
	var cfChar =	 new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
	var cfCharEven = new Array(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25);
	var cfCharOdd =  new Array(1,0,5,7,9,13,15,17,19,21,1,0,5,7,9,13,15,17,19,21,2,4,18,20,11,3,6,8,12,14,16,10,22,25,24,23);
	var cfCode =	 new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
	var cfLen1 = cf.length - 1;
	var cfLen2 = 0;
	var cfTot1 = 0;
	var cfTot2 = 0;
	var cfC = "";
	while( cfLen1-- )
	{
		cfC = cf.charAt(cfLen1);
		cfLen2 = (cfLen1 + 1) / 2;
		if ( parseInt( cfLen2 ) == cfLen2 )
		{
			cfCharLen = cfChar.length;
			while( cfCharLen-- )
				if ( cfChar[ cfCharLen ] == cfC )
					cfTot1 += cfCharEven[ cfCharLen ];
		}
		else
		{
			cfCharLen = cfChar.length;
			while( cfCharLen-- )
				if ( cfChar[ cfCharLen ] == cfC )
					cfTot1 += cfCharOdd[ cfCharLen ];
		}
	}
	cfTot2 = cfTot1 - parseInt(cfTot1 / 26) * 26;
	return cf.charAt(cf.length - 1) == cfCode[ cfTot2 ];
}

function checkPIVA( obj )
{
	var piva = document.getElementById( obj ).value.toUpperCase();
	var pivaLen1 = piva.length - 1;
	var pivaLen2 = 0;
	var pivaTot1 = 0;
	var pivaTot2 = 0;
	var pivaTot3 = 0;
	var pivaTot4 = 0;
	var pivaCode = 0;
	var pivaC = "";
	while( pivaLen1-- )
	{
		pivaC = parseInt( piva.charAt(pivaLen1) );
		
		pivaLen2 = (pivaLen1 + 1) / 2;
		if ( parseInt( pivaLen2 ) == pivaLen2 )
		{
			//alert('pari '+pivaC);
			if ( pivaC >= 5 ) pivaTot3++;
			pivaTot1 += pivaC;
		}
		else
		{
			//alert('dispari '+pivaC);
			pivaTot2 += pivaC;
		}
	}
	alert('pari '+pivaTot1);
	alert('dispari '+pivaTot2);
	alert('>=5 '+pivaTot3);
	pivaTot4 = pivaTot2 + (pivaTot1 * 2) + pivaTot3;
	alert('somma '+pivaTot4);
	pivaTot4 -= parseInt(pivaTot4 / 10) * 10;
	alert('mod '+pivaTot4);
	pivaCode = 10 - pivaTot4;
	alert( piva.charAt(piva.length - 1)+' == '+pivaCode )
	return piva.charAt(piva.length - 1) == pivaCode;
}

function right(e) {
	if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))	{
		alert("1");
		return false;
	} else if (navigator.appName == 'Microsoft Internet Explorer' && (e.button == 2 || e.button == 3)) {
		alert("2");
		return false;
	}
	alert("3");
	return false;
}
//document.captureEvents(Event.MOUSEDOWN);
//document.onmousedown=right;
//document.oncontextmenu = false;
document.oncontextmenu=new Function("return false");

function valueForm( tipo )
{
	var objForm = document.forms[0];
	var totElements = objForm.elements.length;
	var retParam = "";
	
	while ( totElements-- )
	{
		typeElement = objForm.elements[totElements].type;
		if ( typeElement == "text" || typeElement == "hidden" || typeElement == "select-one" || typeElement == "radio" || typeElement == "checkbox" )
		{
			if ( objForm.elements[totElements].getAttribute("submit") != null && tipo )
			{
				if ( retParam != "" ) retParam+= "&";
				retParam+= objForm.elements[totElements].name+"="+objForm.elements[totElements].value;
			}
			else if ( objForm.elements[totElements].getAttribute("nosubmit") == null && ! tipo )
			{
				if ( retParam != "" ) retParam+= "&";
				retParam+= objForm.elements[totElements].name+"="+objForm.elements[totElements].value;
			}
		}
	}
	return retParam;
}
</script>

<br />
<br />
<input type="checkbox" name="test1"  value="Test Prova" nosubmit />

<br />

<input type="text" name="test" id="test" value="" />

<br />
<select name="ciccio">
	<option value="pippo">pippo</option>
	<option value="ciccio">ciccio</option>
	<option value="tizio">tizio</option>
</select>
<br />
<input type="button" onclick="alert( checkPIVA( 'test' ) )" value="Submit" />
<br />

<center>
<img src="images/avvisiMenu.png" alt="fail" width="10" height="10" onmousedown="right(event)"/>
<embed src="images/adjustrgb.svgz" width="50" height="50"  
		pluginspage="http://download.adobe.com/pub/adobe/magic/svgviewer/win/3.x/3.03/en/SVGView.exe" 
		classid="clsid:78156a80-c6a1-4bbf-8e6a-3cd390eeb4e2" />

<!--object data="images/adjustrgb.svg" width="1000" height="1000"  type="image/svg+xml" 
		codebase="http://download.adobe.com/pub/adobe/magic/svgviewer/win/3.x/3.03/en/SVGView.exe" 
		classid="clsid:78156a80-c6a1-4bbf-8e6a-3cd390eeb4e2" -->
<!--object data="images/adjustrgb.svg" width="1000" height="1000"  type="image/svg+xml" -->
<!-- no param -->
	<!--img src="images/avvisiMenu.png" alt="fail" width="50" height="50" /-->
<!--/object-->


</center>
<input type="hidden" id="sessid" name="sessid" value="{$sessid}" />

</form>


</body>
</html>
